#include <queue>
#include <string>
#include <iostream>
using std::queue;
using std::string;
using std::cin;
using std::cout;
using std::endl;

//#define DEBUG


class MagicBlock
{
public:
    int x[4];// = {1,2,3,4};
    int y[4];// = {8,7,6,5};

public:
    MagicBlock()
    {
        x[0] = 1;
        x[1] = 2;
        x[2] = 3;
        x[3] = 4;
        y[0] = 8;
        y[1] = 7;
        y[2] = 6;
        y[3] = 5;
    }
    
    void opA()
    {
        int z;
        for(int i=0;i<4;++i)
        {
            z = x[i];
            x[i] = y[i];
            y[i] = z;
        }
    }
    
    void opB()
    {
        int z = x[3];
        for(int i=3;i>=1;--i) x[i] = x[i-1];
        x[0] = z;
        
        z = y[3];
        for(int i=3;i>=1;--i) y[i] = y[i-1];
        y[0] = z;
    }
    
    void opC()
    {
        // x[1] -> x[2] -> y[2] -> y[1] -> x[1];
        int z = x[1];
        x[1] = y[1];
        y[1] = y[2];
        y[2] = x[2];
        x[2] = z;
    }
    
    bool operator ==(const MagicBlock& other)
    {
        for(int i=0;i<4;++i)
        {
            if(x[i]!=other.x[i] || y[i]!=other.y[i]) return false;
        }
        
        return true;
    }
};


struct QNode
{
    MagicBlock mb;
    string ops;// = "";
    
    QNode() { ops = ""; }
    
    bool checkBranch()
    {
        int xlen = ops.length()-1;
        if(xlen>=1)
        {
            if(ops[xlen]=='A' && ops[xlen-1]=='A') return false;
            
            if(xlen>=3)
            {
                if(ops[xlen]=='B' && ops[xlen-1]=='B' && ops[xlen-2]=='B' && ops[xlen-3]=='B') return false;
                if(ops[xlen]=='C' && ops[xlen-1]=='C' && ops[xlen-2]=='C' && ops[xlen-3]=='C') return false;
            }
        }
        
        return true;
    }
};


string find(MagicBlock origin, MagicBlock desire)
{
    queue<QNode> q;
    QNode qn;
    qn.mb = origin;
    q.push(qn);
    
    while(true)
    {
        qn = q.front();
        qn.ops += "A";
        if(qn.checkBranch())
        {
            qn.mb.opA();
            if(qn.mb == desire) return qn.ops;
            q.push(qn);
        }
        
        qn = q.front();
        qn.ops += "B";
        if(qn.checkBranch())
        {
            qn.mb.opB();
            if(qn.mb == desire) return qn.ops;
            q.push(qn);
        }
        
        qn = q.front();
        qn.ops += "C";
        if(qn.checkBranch())
        {
            qn.mb.opC();
            if(qn.mb == desire) return qn.ops;
            q.push(qn);
        }
        
        q.pop();
    }
}


int main()
{
    int steps;
    MagicBlock mbOri, mbDes;
    
    while(cin>>steps && steps>-1)
    {
        // Input desired magic block state
        for(int i=0;i<4;++i) cin >> mbDes.x[i];
        for(int i=0;i<4;++i) cin >> mbDes.y[i];
        
        #ifdef DEBUG
        cout << "[DEBUG] Begin ==>>" << endl;
        for(int i=0;i<4;++i) cout << mbDes.x[i] << " "; cout << endl;
        for(int i=0;i<4;++i) cout << mbDes.y[i] << " "; cout << endl;
        cout << "[DEBUG] End   ==<<" << endl;
        #endif
        
        // Calculate the path
        string res = find(mbOri, mbDes);
        if(res.length() > steps)
        {
            cout << -1 << endl;
            continue;
        }
        cout << res.length() << " " << res << endl;
    }
    
    return 0;
}
